<template>
  <div class="m-4 mr-0 overflow-hidden bg-white">
    <BasicTree
      title="物料分类"
      toolbar
      search
      :clickRowToExpand="false"
      :treeData="treeData"
      :fieldNames="{ key: 'key', title: 'title' }"
      @select="handleSelect"
    />
  </div>
</template>
<script lang="ts">
import {ref,onMounted,defineComponent} from 'vue'
  import { BasicTree } from '/@/components/Tree';
  import { queryMaterialTreeList } from '../../material.api.ts';

  export default defineComponent({
    name: 'DeptTree',
    components: { BasicTree },

    emits: ['select'],
    setup(_, { emit }) {
      const treeData = ref([]);

      async function fetch() {
        const {result,success} = await queryMaterialTreeList()
        if(success){
          treeData.value=result
        }
      }

      function handleSelect(keys) {
        emit('select', keys[0]);
      }

      onMounted(() => {
        fetch();
      });
      return { treeData, handleSelect };
    },
  });
</script>
